package com.example.notificationtest

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.core.app.NotificationCompat
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager


        //显示取消
//        manager.cancel(1)

        //判断版本
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channel =
                NotificationChannel("normal", "Normal", NotificationManager.IMPORTANCE_DEFAULT)
            manager.createNotificationChannel(channel)

            val channel2 = NotificationChannel("important","Important",NotificationManager.IMPORTANCE_HIGH)
            manager.createNotificationChannel(channel2)
        }

        sendNotice.setOnClickListener {
            Log.d("MainActivity", "test")
            var intent = Intent(this, NotificationActivity::class.java)
            var pi = PendingIntent.getActivity(this,0,intent,0)
//            val notification = NotificationCompat.Builder(this, "normal")
//                .setContentTitle("This is content title")
////                .setContentText("Learn how to build notifications, send and sync data,\n" +
////                     "and use voice actions.Get the official Android IDE and developer tools to\n" +
////                        "build apps for Android")
////                .setStyle(NotificationCompat.BigTextStyle().bigText("Learn how to build notifications, send and sync data,\n" +
////                  "and use voice actions.Get the official Android IDE and developer tools to\n" +
////                      "build apps for Android"))
//                .setStyle(NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(resources, R.drawable.alpha03)))
//                .setSmallIcon(R.drawable.alpha03)
//                .setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.alpha03))
//                .setContentIntent(pi)
//                .setAutoCancel(true)  //点击取消
//                .build()
            var notification = NotificationCompat.Builder(this,"important")
                .setContentTitle("This is a important title")
                .setContentText("Important context")
                .setSmallIcon(R.drawable.alpha03)
                .setLargeIcon(BitmapFactory.decodeResource(resources,R.drawable.alpha03))
                .setContentIntent(pi)
                .setAutoCancel(true)
                .build()
            manager.notify(1, notification)
        }
    }
}